<html>
	<title>A unit test for drw.SystemUnderTest class</title>
	<head>
		<script type='text/javascript' src='../app/jsUnitCore.js'></script>
		<script type='text/javascript' src='../../jquery.js'></script>
		<script type='text/javascript' src='../../js/query.js'></script>
		<script type='text/javascript'>


		//set 
				var em = {};

			// set test version 
			em.test = true;
			em.droid = false;

		
		var host  = "http://k2.emrosswar.com/game/";
		var jsoncb = "jsonpcallback=?";
		var key = "&key=3badb54bda7e38920062ad493d1c9944";
		// var droid = "&_p=EW-DROID";
		var droid = "";

		
			function debug_log(msg) {
				console.log(msg);
			}

			var query;
			function setUp() {
				// perform fixture set up

			}

			function tearDown() {
				// clean up
			}

			function test_worldmap() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					x : 224,
					y : 250
				};
				query = new CQuery();
				query.makeQuery('worldmap');
				query.setCoOdi(param.x, param.y);
				if(!query.validate()) {
					debug_log(" Not valid world map query set ");
					query.dump();
				}
var expected_url = host + "api_world_map.php?" + jsoncb + key + "&x=224&y=250&_l=en" +droid;
		//		var expected_url = "http://k2.emrosswar.com/game/api_world_map.php?jsonpcallback=?&key=3badb54bda7e38920062ad493d1c9944&x=224&y=250&_l=en";
				assertEquals(" query world map ", expected_url, query.url);

			}

			
			
			
			function test_getcityinfo() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum : 3070,
				};
				query = new CQuery();
				query.makeQuery('getcit');
				query.setCit( param.citnum);
				
				assertTrue(query.validate()) ;

				var expected_url = host + "get_cityinfo_api.php?" + jsoncb + key + "&city=3070&_l=en" +droid;
				assertEquals(" query world map ", expected_url, query.url);

			}
			
			function test_solEdu() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum : 3070,
				};
				query = new CQuery();
				query.makeQuery('sol_edu');
				query.setCit(param.citnum);
				
				assertTrue(query.validate()) ;

				var expected_url = host + "soldier_educate_api.php?" + jsoncb + key + "&city=3070&_l=en" +droid;
				assertEquals(" query test_solEdu ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
			}			

		function test_conscribe() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum : 14281,
				};
				query = new CQuery();
				query.makeQuery('conscribe');
				query.setCit( param.citnum);
				
				assertTrue(query.validate()) ;

				var expected_url = host + "gen_conscribe_api.php?" + jsoncb + key + "&city=14281&action=gen_list&extra=1&_l=en" +droid;
				
				assertEquals(" query conscribe  ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
				
			}	

			
			
			
			function test_armament_set_ta() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum: 14281,
					atttype: 7,
					genid: 185,
					x : 204,
					y : 251,
					solnum: 33,
				};
				var query = new CQuery();
				query.makeQuery('armament_set_ta');
				query.setCit( param.citnum);
				query.setCoOdi( param.x, param.y );		

				var expected_url = host + "armament_action_do_api.php?" 
						+ jsoncb + key + "&city=14281&act=anum&x=204&y=251&_l=en" +droid;
				assertEquals(" query test_armament_set_ta ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
			}
	
			function test_armament_att() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum: 14281,
					atttype: 7,
					genid: 185,
					x : 204,
					y : 251,
					 troops : { o:244},
				};
			var query = new CQuery();
			query.makeQuery('armament_att');
			query.setCit( param.citnum);
			query.setAttType( param.atttype);
			query.setHGenId( param.genid);
			query.setCoOdi( param.x, param.y );
			query.setSolNum( param.troops);
			

				var expected_url = host + "armament_action_do_api.php?" 
						+ jsoncb + key + "&city=14281&action=do_war&attack_type=7&gen=185&area=204&area_x=251&soldier_num15=244&_l=en" +droid;
				assertEquals(" query test_armament_att ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
			}
			
			function test_armament_att_wcost() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum: 14281,
					atttype: 7,
					genid: 185,
					x : 204,
					y : 251,
					 troops : { o:244},
				};
				var query = new CQuery();
				query.makeQuery('armament_att_wcost');
				query.setCit( param.citnum);
				query.setAttType( param.atttype);
				query.setHGenId( param.genid);
				query.setCoOdi( param.x, param.y );
				query.setSolNum( param.troops);
				query.setCost({"carry":1980,"cost_food":1980,"cost_wood":0,"cost_iron":0,"cost_gold":0,"distance":2160,"travel_sec":300} );		

				var expected_url = host + "armament_action_task_api.php?" 
						+ jsoncb + key + "&city=14281&action=do_war&attack_type=7&gen=185&area=204&area_x=251&soldier_num15=244&_l=en"
						+ droid
						+ "&carry=1980&cost_food=1980&cost_wood=0&cost_iron=0&cost_gold=0&distance=2160&travel_sec=300"
						;
				assertEquals(" query test_armament_att_wcost ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
			}



		function test_scan_armament_att() {
				// instantiating a SystemUnderTest, a class in the drw namespace

				var param = {
					citnum: 3070,
					atttype: 3,
					genid: undefined,
					x : 184,
					y : 53,
					troops : undefined,
					tainum: 1,
				};
				var query = new CQuery();
				query.makeQuery('armament_att');
				query.setCit( param.citnum);
				query.setAttType( param.atttype);
				query.setHGenId( param.genid);
				query.setCoOdi( param.x, param.y );
				// query.setSolNum( param.troops);
				query.setTaiNum(param.tainum);

				var expected_url = host + "armament_action_do_api.php?" 
						+ jsoncb + key + "&city=3070&action=do_war&attack_type=3&tai_num=1&area=184&area_x=53&_l=en" +droid;
				assertEquals(" query test_armament_att ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
			}
			

function test_scan_armament_att_wcost() {

				var param = {
					citnum: 3070,
					atttype: 3,
					genid: undefined,
					x : 184,
					y : 53,
					troops : undefined,
					tainum: 1,
				};
				var query = new CQuery();
				query.makeQuery('armament_att_wcost');
				query.setCit( param.citnum);
				query.setAttType( param.atttype);
				query.setHGenId( param.genid);
				query.setCoOdi( param.x, param.y );
				// query.setSolNum( param.troops);
				query.setTaiNum(param.tainum);
				
				query.setCost({"carry":180,"cost_food":180,"cost_wood":0,"cost_iron":0,"cost_gold":0,"distance":2040,"travel_sec":0});		

				var expected_url = host + "armament_action_task_api.php?" 
						+ jsoncb + key + "&city=3070&action=do_war&attack_type=3&tai_num=1&area=184&area_x=53&_l=en" 
						+droid
						+ "&carry=180&cost_food=180&cost_wood=0&cost_iron=0&cost_gold=0&distance=2040&travel_sec=0"
						;
				assertEquals(" query test_armament_att_wcost ", expected_url, query.url);
				debug_log( expected_url );
				debug_log( query.url );
		};
			

function test_scanres_messageapi () {

				var param = {
					citnum: 3070,
					pagenum: 1,
				};
				var query = new CQuery();
				query.makeQuery('messageapi');
				query.setPage( param.pagenum);
			


				var expected_url = host + "message_api.php?" 
						+ jsoncb + key + "&page=1&_l=en" 
						+ droid;
				assertEquals(" query test_scanres_messageapi ", expected_url, query.jsonpurl +'&' + query.data);
				debug_log( expected_url );
				debug_log( query.url );
		};
	
	function test_scanres_list() {

				var param = {
					citnum: 3070,
					pagenum: 1,
					listtype: 3,
				};
				var query = new CQuery();
				query.makeQuery('wresultlist');
		
				query.setPage( param.pagenum);
				query.setListType( param.listtype);
					

				var expected_url = host + "war_result_list_api.php?" 
						+ jsoncb + key + "&page=1&type=3&_l=en" 
						+ droid;
				assertEquals(" query test_scanres_list ", expected_url, query.jsonpurl +'&' + query.data);
				debug_log( expected_url );
				debug_log( query.url );
		};		

	function test_scanres_info() {

				var param = {
					citnum: 3070,
					msgid: 3276196,
				};
				var query = new CQuery();
				query.makeQuery('wresultinfo');
				query.setMsgid( param.msgid);					

				var expected_url = host + "war_result_info_api.php?" 
						+ jsoncb + key + "&id=3276196&_l=en" 
						+ droid;
				assertEquals(" query test_scanres_info ", expected_url, query.jsonpurl +'&' + query.data);
				debug_log( expected_url );
				debug_log( query.url );
		};		



		</script>
	</head>
	<body/>
</html>